#pragma once
#include <memory>
#include <map>
#include <mutex>
#include <vector>
#include "InputSource.h"
#include "SqlTableOp.h"

namespace Media{
    class InputSourceManager{
    public:
        using Ptr = std::shared_ptr<InputSourceManager>;
        static Ptr Instance();
        InputSourceManager();
        ~InputSourceManager();


        bool AddSource(const inputSourceTable& config, uint32_t& id);
        bool RemoveSource(uint32_t id);
        bool GetOneSourceConfig(uint32_t id, inputSourceTable& config);
        bool GetAllSourceConfig(std::vector<inputSourceTable>& configs);
        
        InputSource::Ptr GetSource(uint32_t id);

    private:
        void init();
        void inputLocalInterfaceCheck();

        static InputSource::Ptr createInputSource(const SourceConfig& config);
        std::map<InputSource::InputSourceId, InputSource::Ptr> m_sources;
        std::recursive_mutex m_mux;
        SqlTableOp::Ptr m_sql;
    };

}